<template>
  <div class="f2bpm-page-layout">
    <div style="width: 100%; margin: 0;clear: both">
      <div style="padding: 5px;" border="false">
        <div id="box" class="fence-box" style="width: 98%">
          <div style="padding-left: 10px; text-align: left;">
            <i class="fa fa-cube" aria-hidden="true"></i>传递分发：
          </div>
          <div class="fence-inner-line column-height" style="width: 99%; height: 390px;">
            <table id="tableList" class="common-table" cellpadding="0" cellspacing="0">
              <tr>
                <td class="leftTdbg">目标用户：</td>
                <td style="width: 630px; text-align: left;">
                  <el-input style="width: 65%" readonly="readonly" v-model="data.actorsDes" placeholder="请选择要沟通的目标用户" size="mini"></el-input>
                  <a role="button" id="select_btn" @click="selectorUserTextValue('actors','actorsDes');" class="btn btn-success btn-sm mr2">
                    <i class="fa  fa-search"></i>选择目标用户
                  </a>
                  <a   role="button" id="add_btn" @click="sureSave" class="btn btn-success btn-sm mr2">
                    <i class="fa  fa-save"></i>提交沟通
                  </a>
                </td>
              </tr>
            </table>
            <div style="padding: 3px;">
              <vxe-table :data.sync="treeTableData" :tree-config="{key: 'id', children: 'children', expandAll: true}">
                <vxe-table-column prop="id" type="index" label="#" tree-node></vxe-table-column>
                <vxe-table-column prop="text" label="姓名" width="100"></vxe-table-column>
                <vxe-table-column prop="extend1" label="账号" width="100"></vxe-table-column>
                <vxe-table-column prop="extend2" label="部门" width="100"></vxe-table-column>
                <vxe-table-column prop="extend6" label="处理意见" width="180"></vxe-table-column>
                <vxe-table-column prop="extend4" label="创建时间" width="140"></vxe-table-column>
                <vxe-table-column prop="extend5" label="完成时间" width="140"></vxe-table-column>
              </vxe-table>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    watch: {
      treeFilterText(val) {
        this.$refs.mytree.filter(val);
      }
    }
    , computed: {
      countGridHeight() {
        return $(document).height() - global_datagridHeightDiff;
      }
      , rotateIcon() {
        return this.isCollapsed ? 'fa fa-angle-double-right' : 'fa fa-angle-double-left';
      }
    }
    , created() {
      var that = this;
      var taskId = Object.toQueryString("taskId") || "";
      var wiid = Object.toQueryString("wiid") || "";
      var type = Object.toQueryString("type") || "";
      var parms = {};
      var parmsStr = Object.toQueryString("parms");
      var parms = {};
      if (parmsStr) {
        parmsStr = decodeURIComponent(parmsStr);
        parms = eval("(" + parmsStr + ")");
      }
      window.parms = parms;
      that.taskId = taskId;
      that.wiid = wiid;
      that.type = type;
      let currUser =  that.$store.getters.getState.author;

      //加载页面Model数据
      var jsonData = Object.toAjaxJson("/workflow/workflowBusiness/", "getTaskdisterJson", { taskId: that.taskId, type: that.type, wiid: that.wiid })
      that.treeTableData = jsonData;
      console.info(jsonData);
    }
    , data() {
      return {
        //url参数
        wiid: "",
        taskId: "",
        type: "",
        //======数据============
        treeTableData: [],
        data: {
          actors: "",
          actorsDes: ""
        }
      };
    },

    methods: {
      selectorUserTextValue(inputKey, inputName, passParm, singleSelect, keyName, width, height) {
        var that = this;
        WF.SelectorDialog.selectorUserTextValue(that, inputKey, inputName, passParm, singleSelect, keyName, width, height)
      }
      , sureSave() {
        var that = this;
        var method = "taskdisterSender";
        switch (that.type) {
          case "taskdister":
            //发送任务分发实例
            method = "taskdisterSender";
            break;
          case "taskCommunication":
            //发送沟通任务
            method = "sendToNextTaskCommunication";
            break;
          default:
            break;
        }
        if (type == "taskCommunication" && that.treeTableData.length > 1) {
          FUI.Window.showMsg("已存在沟通用户");
          return;
        }
        var actors = that.data.actors;
        if (actors != "" && actors != "[]") {
          var result = Object.toAjaxJson(__webpath + "/workflow/workflowformSender/", method, {
            "taskId": taskId,
            "type": type,
            "actorJson": actors
          });
          if (result.success) {
            that.data.actors = "";
            that.data.actorsDes = "";
            FUI.Window.showMsg(result.msg, null, 1, function () {
              //关闭后刷新父页面
              if (type == "taskCommunication") {
                FUI.Window.closeEdit();
                parent.window.location.reload();
              }
            });
          } else {
            FUI.Window.showMsg(result.msg);
          }

        } else {
          FUI.Window.showMsg("请选择分发目标人员");
        }
      }
      , getResult() {
        var that = this;
        return that.data;
      }
    }
    , mounted() {
    }
  }


  window.getResult = function () {
    return myvm.getResult();
  }
</script>
<style lang="scss" scoped>
    @import url("@/static/css/workflowform.css");
  </style>